package com.minelx.datamicroscope.core;

import com.alibaba.fastjson.JSONObject;
import com.minelx.datamicroscope.core.query.Query;
import io.gitee.minelx.filesystem.Directory;
import com.minelx.woods.data.Task;

import static io.gitee.minelx.filesystem.init.OpenPolicy.CREATE;

public class NewTaskDealer {
    private final Directory downloadingDirectory;

    public NewTaskDealer(Directory downloadingDirectory) {
        this.downloadingDirectory = downloadingDirectory;
    }

    public void deal(Task task) {
        JSONObject infoAsJSON = task.values().getInfo();
        // write content out
        Query.localFSAndOnlineIndexWithPandasCalculationSupport(infoAsJSON)
                .queryTo(downloadingDirectory
                        .child().file(task.values().getId(), CREATE)
                        .path().uri());
    }
}
